# Convenience methods for converting between Gosu degrees, radians, and Vec2 vectors
class Numeric 
  def gosu_to_radians
    (self - 90) * Math::PI / 180.0
  end
  
  def radians_to_gosu
    self * 180.0 / Math::PI + 90
  end
  
  def radians_to_vec2
    CP::Vec2.new(Math::cos(self), Math::sin(self))
  end
end

module CP
  class Vec2
    def angle_to(other_vec)
      Gosu::angle(self.x, self.y, other_vec.x, other_vec.y)
    end
  end
end

module Math
  module Easing
    def self.linear_tween(t,b,c,d)
      return c*t/d + b
    end
  end
end

module Gosu
  class Window
    def draw_quad_with_coords(topleft, bottomright, color=0xaa000000, zorder=1)
      draw_quad(topleft.x, topleft.y, color,
                topleft.x, bottomright.y, color,
                bottomright.x, topleft.y, color,
                bottomright.x, bottomright.y, color, zorder
                )
    end
    
    def init_keyboard_constants()
      ('a'..'z').each do |letter|
        eval "Gosu::Kb#{letter.upcase} = #{char_to_button_id(letter)}"
      end
    end
    
  end
end


class Object
  def log(string)
    puts self.to_s + ": " + string
  end
end

def colour_for_value(value, max)
  
  red = ((100 - c.percent_ready) * 2.55).to_i
  green = (c.percent_ready * 2.55).to_i
  puts red,green
  ready_colour = Gosu::Color.new(255, red, green, 0)
end

module BaseShapes
  Box = [CP::Vec2.new(-25.0, -25.0), CP::Vec2.new(-25.0, 25.0), 
    CP::Vec2.new(25.0, 25.0), CP::Vec2.new(25.0, -25.0)]
  
  Crawler = [CP::Vec2.new(-25.0, -18.0), CP::Vec2.new(-25.0, 18.0), 
      CP::Vec2.new(25.0, 18.0), CP::Vec2.new(25.0, -18.0)]
      
  Tank = [CP::Vec2.new(-25.0, -18.0), CP::Vec2.new(-25.0, 18.0), 
      CP::Vec2.new(25.0, 18.0), CP::Vec2.new(25.0, -18.0)]
  
  Shot = [CP::Vec2.new(-5.0, -5.0), CP::Vec2.new(-5.0, 5.0), 
      CP::Vec2.new(5.0, 5.0), CP::Vec2.new(5.0, -5.0)]
end

module ZOrder
  Background = 0
  Objects = 1
  AirObjects = 2
  GUI = 3
end

def objects_within_range(position, range)
  objects = $game.objects.clone
  
  objects.reject! {|obj|
    !(obj.is_a? MovableObject) or !(obj.body.p.near? position, range)
  }
  return objects
end

def vect(x,y)
  CP::Vec2.new(x,y)
end

class Point
  attr_accessor :x, :y
  
  def initialize
    @x = @y = 0
  end
  
  def initialize(x,y)
    @x,@y = x,y
  end
end

Gosu::KbLetters = {}


def init_keyboard_constants()
  ('a'..'z').each do |letter|
    #eval "Gosu::Kb#{letter.upcase} = #{Gosu::Window.char_to_button_id(letter)}"
  end
end

init_keyboard_constants
